//
// Created by zhengbo on 23-4-18.
//

#include <GL/gl.h>
#include "LidarPoints.h"

LidarPoints::LidarPoints(float* data, int count) {
    this->mCount = count;
    glGenBuffers(1, &mVbo);
    glBindBuffer(GL_ARRAY_BUFFER, mVbo);
    glBufferData(GL_ARRAY_BUFFER, count * sizeof(float), data, GL_STATIC_DRAW);
}

void LidarPoints::Update() {}

void LidarPoints::Render() {
    glEnableClientState(GL_VERTEX_ARRAY);
    glBindBuffer(GL_ARRAY_BUFFER, mVbo);
    glVertexPointer(3, GL_FLOAT, 0, 0);
    glDrawArrays(GL_POINTS, 0, mCount);
    glDisableClientState(GL_VERTEX_ARRAY);
}

void LidarPoints::InitBuffer() {
    if (mVbo == 0) {
        glGenBuffers(1, &mVbo);
    }
}

void LidarPoints::ReleaseBuffer() {
    if (mVbo != 0) {
        glDeleteBuffers(1, &mVbo);
        mVbo = 0;
    }
}

